package com.hzvtc.bosswang.manageuser.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzvtc.bosswang.managecommon.domain.AjaxResult;
import com.hzvtc.bosswang.manageuser.domain.Class;
import com.hzvtc.bosswang.manageuser.domain.Grade;
import com.hzvtc.bosswang.manageuser.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/class-manager")
public class ClassController {

    @Autowired
    private ClassService classService;

    @PostMapping("/add-class")
    private AjaxResult addClass(@RequestBody Class iclass){
        if (classService.addClass(iclass)>0){
            return new AjaxResult(200,"添加成功",null);
        }
        return new AjaxResult(500,"添加失败",null);
    }

    @PostMapping("/edit-class")
    private AjaxResult editClass(@RequestBody Class iclass){
        if (classService.editClass(iclass)>0){
            return new AjaxResult(200,"修改成功",null);
        }
        return new AjaxResult(500,"修改失败",null);
    }

    @GetMapping("/view-class/{id}")
    private AjaxResult selectClassById(@PathVariable Long id){
        Class iclass = classService.selectClassById(id);
        if (iclass!=null){
            return new AjaxResult(200,"查询成功！",iclass);
        }
        return new AjaxResult(500,"查询失败",null);
    }

    @PostMapping("/list-class")
    private AjaxResult listClass(@RequestBody Class iclass){
        Page<Class> page=new Page<>();
        page.setSize(10);
        page.setCurrent(1);
        return new AjaxResult(200,"查询成功！", classService.listClass(page,iclass));
    }

    @DeleteMapping("/delete-class/{id}")
    private AjaxResult deleteClass(@PathVariable Long id){
        if (classService.deleteClass(id)>0){
            return new AjaxResult(200,"删除成功",null);
        }
        return new AjaxResult(500,"删除失败",null);
    }

}
